import vue from 'vue'
import XVerify from './XVerify'
import xurl from './xurl'
import XCookie from "./XCookie";

export default {
    /**
     * 发送语音验证码
     * @param phone
     * @param callback
     */
    sendVoiceCode(phone, callback) {
        if (XVerify.isPhone(phone)) {
            xurl.putSync(vue.prototype.NW_API_vue + '/voice/code/send/phone/' + phone).then(data => {
                if (data.success) {
                    callback(data)
                } else {
                    console.log('sendVoiceCode error : ' + data.errMsg)
                }
            }).catch(error => {
                console.log('sendVoiceCode error : ' + error.message)
            })
        } else {
            console.log('sendVoiceCode：手机号格式不正确')
        }
    },
    /**
     * 注册发送验证码
     * @param phone
     * @param callback
     */
    sendRegisterCode(phone, callback) {
        if (XVerify.isPhone(phone)) {
            xurl.putSync(vue.prototype.NW_API_vue + '/register/code/send/phone/' + phone).then(data => {
                if (data.success) {
                    callback(data)
                } else {
                    console.log('sendRegisterCode error : ' + data.errMsg)
                }
            }).catch(error => {
                console.log('sendRegisterCode error : ' + error.message)
            })
        } else {
            console.log('sendRegisterCode：手机号格式不正确')
        }
    },

    /**
     * 忘记密码，发送验证码
     * @param phone
     * @param callback
     */
    sendForgetCode(phone, callback) {
        if (XVerify.isPhone(phone)) {
            xurl.putSync(vue.prototype.NW_API_vue + '/forgetPwd/code/send/phone/' + phone).then(data => {
                callback(data)
            }).catch(error => {
                console.log('sendForgetCode error : ' + error.message)
            })
        } else {
            console.log('手机号格式不正确');
        }
    },
    /**
     * 校验验证码
     * @param phone
     * @param code
     * @param callback
     */
    isCheckCode(phone, code, callback) {
        xurl.putSync(vue.prototype.NW_API_vue + '/register/code/check/phone/' + phone + '/' + code).then(data => {
            if (data.success) {
                callback(data)
            } else {
                console.log('isCheckCode error : ' + data.errMsg)
            }
        }).catch(error => {
            console.log('isCheckCode error : ' + error.message)
        })
    },

    /**
     * 检查手机号是否被注册
     * @param phone
     * @param callback
     */
    isCheckRegisterPhone(phone, callback) {
        xurl.putSync(vue.prototype.NW_API_vue + '/check/regist/phone/' + phone).then(data => {
            if (data.success) {
                callback(data)
            } else {
                console.log('isCheckCode error : ' + data.errMsg)
            }
        }).catch(error => {
            console.log('isCheckRegisterPhone error : ' + error.message)
        })
    }
}
